<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include/src :: form_base_js_and_css"/>
</head>
<body style="background-color: #f2f2f2; height: 100%;">
<style>
	.layui-form-checkbox[lay-skin=primary] {
		height: 25px !important;
	}
</style>
<div id="id_panel">
</div>
<script th:inline="javascript">
	// 表单初始化
	var formObj = null;
	var form1 = null;
	var simple_table= null;
	//使用layui的sku模块
	layui.config({
		//自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
		base: '/static/js/layui_extends/',
		version: true
	}).use(['form', 'jquery', 'laydate', 'YsForm', 'YsModal', 'simple_table_TCC_LogisticsMethodSiteDetail'], function(){
        var $ = layui.jquery,
            form = layui.form,
				laydate = layui.laydate,
				YsForm = layui.YsForm,
				YsModal = layui.YsModal,
				element = layui.element,
				simple_table_TCC_LogisticsMethodSiteDetail = layui.simple_table_TCC_LogisticsMethodSiteDetail;
		form1 = layui.form;
		simple_table = layui.simple_table_TCC_LogisticsMethodSiteDetail;
		/*
		* 表单初始化
		* 参数1：表单配置参数
		* 参数2：子表配置参数
		*/
		formObj = YsForm.init({
			id:'id_panel', // 页面容器ID
			dto: $.parseJSON(JSON.stringify([[${dto}]])),
			subGridConfig: {
				name: 'simple_table_TCC_LogisticsMethodSiteDetail',
				data: $.parseJSON(JSON.stringify([[${detail.tccLogisticsOne}]])),
				data2: $.parseJSON(JSON.stringify([[${detail.tccLogisticsTwo}]])),
				data3: $.parseJSON(JSON.stringify([[${detail.tccLogisticsThree}]])),
				data4: $.parseJSON(JSON.stringify([[${detail.tccLogisticsFour}]])),
				data5: $.parseJSON(JSON.stringify([[${detail.tccLogisticsFive}]])),
				data6: $.parseJSON(JSON.stringify([[${detail.tccLogisticsSix}]])),
				onProcess: [[${onProcess}]], LogisticsMethodId: [[${detail.id}]]
			}
		});
		if([[${onProcess}]]=='1'){
			//隐藏头部按钮
			$('#' + formObj.c.id_header).hide();
		}

		$('#' + formObj.c.id_header).find('.bg_color_white').find('.layui-inline').append('<button type="button" class="layui-btn layui-btn-normal" id="logisticsDetails"  onclick="uploadLogistics()">同步物流渠道</button>');

	});

	/**
	 * 同步物流渠道
	 */
	function uploadLogistics() {
		window.matchValuesAfterModalSelectRadio = function(colCode, data, extraData) {
			showloadings(true);
			//查询物流渠道的子列表信息
			$.ajax({
				url: '/api/inter/tccLogisticsChannelMaint/searchZb',
				data: "id=" + data.id,
				type: 'POST',
				async: true,
				success: function(res) {
					showloadings(false);
					if (res.code == 0) {
						formObj.setValueByName("cck", data.cck)
						formObj.setValueByName("vck", data.vck)
						formObj.setValueByName("remark", data.remark)
						formObj.setValueByName("destinationCountryCode", data.country)
						formObj.setValueByName("destinationCountryName", data.countryName)
						formObj.setValueByName("transportationId", data.transportationId)
						formObj.setValueByName("estimatedDayFrom", data.estimatedDayFrom)
						formObj.setValueByName("estimatedDayTo", data.estimatedDayTo)
						formObj.setValueByName("divisionalRule", data.divisionalRule)
						formObj.setValueByName("coefficientWeight", data.coefficientWeight)
						formObj.setValueByName("singlePassCrane", data.singlePassCrane)
						formObj.setValueByName("weightCalBySingle", data.weightCalBySingle)
						formObj.setValueByName("singleBoxReqAmountMin", data.singleBoxReqAmountMin)
						formObj.setValueByName("singleBoxReqAmountMax", data.singleBoxReqAmountMax)
						formObj.setValueByName("clearanceOpeAmount", data.clearanceOpeAmount)
						formObj.setValueByName("freeProNameNum", data.freeProNameNum)
						formObj.setValueByName("maxProNameNum", data.maxProNameNum)
						formObj.setValueByName("additionalStandardAmount", data.additionalStandardAmount)

						// 清空清关方式原有选项
						$('#nameLogsticsClearance').empty();


						var newOptions = MAP_DICT["LogsticsClearance"]
						// 添加新的选项
						for(var i = 0; i < newOptions.length; i++){
							if (i == data.nameLogsticsClearance){
								$('#nameLogsticsClearance').append('<option selected value="' + newOptions[i].value + '">' + newOptions[i].name + '</option>');
							}else {
								$('#nameLogsticsClearance').append('<option value="' + newOptions[i].value + '">' + newOptions[i].name + '</option>');
							}
						}

						// 清空约分规则原有选项
						$('#divisionalRule').empty();

						var newOptions1 = MAP_DICT["divisionalRule"]
						for(var i = 0; i < newOptions1.length; i++){
							if (i == data.divisionalRule){
								$('#divisionalRule').append('<option selected value="' + newOptions1[i].value + '">' + newOptions1[i].name + '</option>');
							}else {
								$('#divisionalRule').append('<option value="' + newOptions1[i].value + '">' + newOptions1[i].name + '</option>');
							}
						}

						// 清空抛货系数原有选项
						$('#coefficientWeight').empty();

						var newOptions2 = MAP_DICT["coefficientWeight"]
						for(var i = 0; i < newOptions2.length; i++){
							if (i == data.coefficientWeight){
								$('#coefficientWeight').append('<option selected value="' + newOptions2[i].value + '">' + newOptions2[i].name + '</option>');
							}else {
								$('#coefficientWeight').append('<option value="' + newOptions2[i].value + '">' + newOptions2[i].name + '</option>');
							}
						}

						// 清空运输类型原有选项
						$('#transportationId').empty();

						var newOptions3 = MAP_DICT["TCC_LogisticsMethod-transportation"]
						for(var i = 0; i < newOptions3.length; i++){
							if (i == data.transportationId){
								$('#transportationId').append('<option selected value="' + newOptions3[i].value + '">' + newOptions3[i].name + '</option>');
							}else {
								$('#transportationId').append('<option value="' + newOptions3[i].value + '">' + newOptions3[i].name + '</option>');
							}
						}

						// 更新select元素
						form1.render('select');

						//给子列表1赋值
						simple_table.c.data = [];
						$('#' + simple_table.c.id).empty();
						for (var i = 0; i < res.data.tccLogisticsOne.length; i++) {
							var rowCurrent = {};
							var row = res.data.tccLogisticsOne[i];
							rowCurrent.heavySn = row.heavySn;
							rowCurrent.heavyEn = row.heavyEn;
							rowCurrent.price = row.price;

							simple_table.addRow(rowCurrent);
						}

						//给子列表2赋值
						simple_table.c.data2 = [];
						for (var i = 0; i < res.data.tccLogisticsTwo.length; i++) {
							var rowCurrent = {};
							var row = res.data.tccLogisticsTwo[i];
							rowCurrent.materialNameCn = row.materialNameCn;
							rowCurrent.materialNameEn = row.materialNameEn;
							rowCurrent.additionalMaterialBilling = row.additionalMaterialBilling;

							simple_table.addRow2(rowCurrent);
						}

						//给子列表3赋值
						simple_table.c.data3 = [];
						for (var i = 0; i < res.data.tccLogisticsThree.length; i++) {
							var rowCurrent = {};
							var row = res.data.tccLogisticsThree[i];
							rowCurrent.heavySn = row.heavySn;
							rowCurrent.heavyEn = row.heavyEn;
							rowCurrent.price = row.price;

							simple_table.addRow3(rowCurrent);
						}

						//给子列表4赋值
						simple_table.c.data4 = [];
						for (var i = 0; i < res.data.tccLogisticsFour.length; i++) {
							var rowCurrent = {};
							var row = res.data.tccLogisticsFour[i];
							rowCurrent.warehouseArea = row.warehouseArea;
							rowCurrent.firstPostalCode = row.firstPostalCode;
							rowCurrent.warehouseCode = row.warehouseCode;
							rowCurrent.additionalBilling = row.additionalBilling;

							simple_table.addRow4(rowCurrent);
						}

						//给子列表5赋值
						simple_table.c.data5 = [];
						for (var i = 0; i < res.data.tccLogisticsFive.length; i++) {
							var rowCurrent = {};
							var row = res.data.tccLogisticsFive[i];
							rowCurrent.vgsbm = row.vgsbm;
							rowCurrent.vgsjc = row.vgsjc;


							simple_table.addRow5(rowCurrent);
						}

						//给子列表6赋值
						simple_table.c.data6 = [];
						for (var i = 0; i < res.data.tccLogisticsSix.length; i++) {
							var rowCurrent = {};
							var row = res.data.tccLogisticsSix[i];
							rowCurrent.warehouseCode = row.warehouseCode;


							simple_table.addRow6(rowCurrent);
						}

						simple_table.listenGrid_1();
						simple_table.listenGrid_2();
						simple_table.listenGrid_3();
						simple_table.listenGrid_4();
						simple_table.listenGrid_5();
						simple_table.listenGrid_6();
						simple_table.reload(simple_table.c);
					}
				},
				error: function() {
					layer.close();
					layer.msg("获取物流渠道子表数据失败，请稍后再试！", {
						icon: 2
					});
				}
			});
		};
		//打开弹出框
		layui.YsModal.init({modalKey: 'TCC_LogisticsChannelMaintPlan', colCode: 'aaaa', parentObj: window});

	}

	//加载中
	function showloadings(t) {
		if (t) {//如果是true则显示loading
			layer.load(2, {
				shade: [0.1, '#000'] //0.1透明度的白色背景
			});
		} else {//如果是false则关闭loading
			layer.closeAll();
		}
	}


</script>

</body>
</html>